package com.lenin.omena.client;

import com.google.gwt.animation.client.Animation;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Element;

public class SlidingAnimation extends Animation {
	
	public enum Direction {
		UP, DOWN;
	}
	
	private int baseLine;
	private int initHeight;
	private int targetHeight;
	private Direction direction;
	
	private HelpPanel element;
	
	public SlidingAnimation(HelpPanel element, int baseLine, 
			int initHeight, int targetHeight, Direction direction) {
		
		this.element = element;
		this.initHeight = initHeight;
		
		this.baseLine = baseLine;
		this.targetHeight = targetHeight;
		this.direction = direction;
	
	}
	
	
	@Override
	public void onUpdate(double progress) {
		
		int height;
		
		if(direction == Direction.UP) {
			height = initHeight + (int)(progress * (targetHeight-initHeight));
		} else {
			height = initHeight + (int)((1-progress) * (targetHeight-initHeight));
		}
		
		int top = baseLine - height;
		
		element.setTop(top);
		element.setHeight(height);
		
	}
	
	@Override
	public void onComplete() {
		super.onComplete();
	}
	
}
